package com.chuangke.common.idgen;

import java.util.Date;
import java.util.Random;

import com.chuangke.common.idgen.orderid.OrderIdWorker;
import com.chuangke.common.idgen.snowflake.SnowflakeIdWorker;
import com.chuangke.common.utils.DateUtils;
import com.chuangke.common.utils.SpringContextUtil;

public class IdManager {

	private static final SnowflakeIdWorker idWorker ;
	
	private static final OrderIdWorker orderIdWorker ;
	
	static {
		idWorker = new SnowflakeIdWorker(0, 0);
		orderIdWorker = SpringContextUtil.getBean(OrderIdWorker.class) ;
	}

	public static String nextId() {
		return idWorker.nextId()+"";
	}
	
	public static String nextOrderId(String bisNo) {
		return orderIdWorker.nextId(bisNo) ;
	}

	public static String nextOrderId(String bisNo,int length) {
		return orderIdWorker.nextId(bisNo,length) ;
	}

	public static String nextSn(String bisNo,int length) {
		return orderIdWorker.nextSn(bisNo,length) ;
	}
	
	public static String nextRandomOrderId(String bisNo) {
		Random rand = new Random();
		return bisNo+DateUtils.getDate(new Date(), "yyMMddHHmmss")+rand.nextInt(10) ;
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 1000; i++) {
			System.out.println(IdManager.nextRandomOrderId("a"));
		}
	}
	
}
